import {Injectable} from '@angular/core';
import {InterfaceProvider} from "@providers/interface";
import {PagingProvider} from "@providers/paging";

/*
  Generated class for the CustomerProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class CustomerProvider {

  constructor(private ifp: InterfaceProvider,
              private paging: PagingProvider,) {
  }

  /**
   * 查询客户信息
   * @param item "PARTYID":partyId,"MRDZ": mrdz,"MOBILE": mobile
   * @returns {Promise<any>}
   */
  getCustomerInfo(item): Promise<any> {
    return this.ifp.post({
      interfaceId: "csm.css.jcdy.qcfwquery.khxx",
      data: item || {}
    }).toPromise();
  }

  /**
   * 设置客户默认收货地址
   * @param partyId "PARTYID":客户id
   * @param id "ID":地址的id
   * @returns {Promise<any>}
   */
  chooseCustomerDefortAddress(partyId, id): Promise<any> {
    return this.ifp.post({
      interfaceId: "csm.yswc.ParytAddress.mraddressUpdate",
      data: {"PARTYID": partyId, "ID": id}
    }).toPromise();
  }

  /**
   * 删除收货地址
   * @param partyId "PARTYID":客户id
   * @param id "ID":地址的id
   * @returns {Promise<any>}
   */
  deleteCustomerAddress(partyId, id): Promise<any> {
    return this.ifp.post({
      interfaceId: "css.fwd.khzl.delete",
      data: {"PARTYID": partyId, "ID": id}
    }).toPromise();
  }

  /**
   * 从地图控件选择地址存为客户收货地址
   * @param item
   */
  addressAdd1(item): Promise<any> {
    return this.ifp.post({
      interfaceId: "css.fwd.khzl.insertyd",
      data: item || {}
    }).toPromise();
  }

  /**
   * 从下拉地址控件选择地址存为客户收货地址
   * @param item
   */
  addressAdd2(item): Promise<any> {
    return this.ifp.post({
      interfaceId: "css.fwd.khzl.insert",
      data: item || {}
    }).toPromise();
  }

  /**
   * 获取故障类型
   * @param item
   */
  getGZLX(item): Promise<any> {
    return this.ifp.post({
      interfaceId: "csm.css.getgzlx",
      data: item || {}
    }).toPromise();
  }

  /**
   * 获取品牌品类
   * @param item
   */
  getPPXX(item): Promise<any> {
    return this.ifp.post({
      interfaceId: "csm.css.getgzlxpp",
      data: item || {}
    }).toPromise();
  }

  /**
   * 获取服务类型
   * @param item
   */
  getFWLX(item): Promise<any> {
    return this.ifp.post({
      interfaceId: "csm.css.jcdy.qcfwquery.fwlx",
      data: item || {}
    }).toPromise();
  }

  /**
   * 新建单据
   * @param item
   */
  addAppointment(item): Promise<any> {
    return this.ifp.post({
      interfaceId: "css.fwd.insert",
      data: item || {}
    }).toPromise();
  }

  /**
   * 新建单据成功后单机信息查询
   * @param item
   */
  queryAppointment(item): Promise<any> {
    return this.ifp.post({
      interfaceId: "csm.css.jcdy.qcfwquery.dqxxsj",
      data: item || {}
    }).toPromise();
  }

  /**
   * 分页查询服务单
   * @param item
   * @param pagingConfig 分页配置
   */
  getMyServerOrders(item, pagingConfig): Promise<any> {
    return this.paging.get({
      interfaceId: "csm.som.cssOrderquery.selectappsorder",
      data: item || {}
    }, pagingConfig).toPromise();
  }

  /**
   * 分页查询订单
   * @param item
   * @param pagingConfig 分页配置
   */
  getMyOrdersList(item, pagingConfig): Promise<any> {
    return this.paging.get({
      interfaceId: "csm.som.cssOrderquery.selectapporder",
      data: item || {}
    }, pagingConfig).toPromise();
  }

  /**
   * 发布评论
   * @param item
   */
  subComment(item): Promise<any> {
    return this.ifp.post({
      interfaceId: "csm.css.qcfw.gdpj.insert",
      data: item || {}
    }).toPromise();
  }

  /**
   * 获取评价类型
   * @param item
   */
  getEvaluationType(item): Promise<any> {
    return this.ifp.post({
      interfaceId: "csm.css.getpjlx",
      data: item || {}
    }).toPromise();
  }

  /**
   * 获取接单师傅的位置
   * @param item
   */
  getMarsterLocation(item): Promise<any> {
    return this.ifp.post({
      interfaceId: "csm.som.jcdy.qcfwtools.geopoint.query",
      data: item || {}
    }).toPromise();
  }
}
